<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@page import="javax.servlet.http.*" %>
<%@page import="java.text.DecimalFormat" %>
<%@page import="nespresso.beans.*" %>
<%@page import="org.apache.commons.logging.*" %>
<html>

<head>
<title>NESPRESSO</title>
<link rel="stylesheet" type="text/css" href="css/nespresso.css" />

<script src="js/jquery-1.7.2.min.js" type="text/javascript"></script>

<script src="js/jquery.dd.js" type="text/javascript"></script>
<link rel="stylesheet" type="text/css" href="css/dd.css" />

<script src="js/jquery.validationEngine.js" type="text/javascript"></script>
<script src="js/jquery.validationEngine-fr.js" type="text/javascript"></script>
<link rel="stylesheet" type="text/css" href="css/validationEngine.jquery.css" />

</head>

<body bgcolor="white" text="black" link="blue" vlink="purple" alink="red">
<% Commande c = (Commande)session.getAttribute("commande");
   if(c == null) { %>Commande nulle <% }
   User currentUser = (User)session.getAttribute("user"); // On récupère le user de la session
   Log log = LogFactory.getLog(this.getClass());%>
<div class="super-div">
<p>&nbsp;</p>
<form name="FLigne" id="FLigne" action="Lignenew" class="f" method="post">
<table border="0" width="50%" align="center">
    <tr>
        <td colspan="4">
            <p align="center"><strong>
            <font class="grosnoir"><%
            if(c.GetId().equals("-NEW-")) out.write("Nouvelle commande");
            else {
            	out.write("Commande N&#176;"); %>
            	</font><font class="grosrouge">
            	<%out.write(c.GetId());%>
            	</font>
            <% } %>
            <font class="grosnoir">- Nouvelle ligne </font></strong></p>
        </td>
    </tr>
    <tr>
        <td width="30%"></td><td width="5%" align="right">
			<font class="petitnoir">Pour : </font></td><td>
            <%
            if(currentUser.getRole().equals("ADMIN")) { // ADMIN : liste des users %> 
            	<select name="s_user" id="s_user"><%
            	Base u = new Base();
           		String nomprenom = new String();
            	u.GetResultat("users");
            	while(u.Suivant()) {
            		nomprenom = u.GetTexte("prenom")+" "+u.GetTexte("nom"); %>
            		<option value="<%=u.GetTexte("id") %>"<%
            		if(currentUser.getId().equals(u.GetTexte("id")))
            			out.write(" selected="+(char)34+"selected"+(char)34); %>
            		 ><%=nomprenom %></option><%            	
           		 }
            	u.Free();
            %>
            </select></td><td width="30%"></td> <%
            } else {
            	Base u = new Base();
            	String nomprenom = new String();
            	u.GetResultat("users", "id", currentUser.getId()); u.Suivant();
            	nomprenom = u.GetTexte("prenom")+ " " + u.GetTexte("nom"); %>
            	<font class="petitbleu"><%=nomprenom %></font><%
            	u.Free();
            } %>
        </td>
    </tr>
</table>
<p>&nbsp;</p>
<div class="divrondform" style="width:800; margin:auto">
    <table border="0" width="98%" height="132" align="center" padding="2px">
		<tr><td height="20px" width="100px"></td><td height="20px" width="265px"></td><td height="20px" width="30px"></td><td height="20px" width="130px"></td></tr>
		
        <tr><td width="100px">
                <p align="right" class="petitblanc">Capsule :&nbsp;</p>
            </td>
            <td width="265px"><select name="capsules" id="capsules" size="1" style="width:280px;height:80px;" >
            	<% 
             	Base cap = new Base();
            	 cap.GetResultat("capsules");
             	while(cap.Suivant()) { %>
             		<option value="<%=cap.GetTexte("id") %>" <%
                	if(cap.GetTexte("image") != null) %> title="icons/<%=cap.GetTexte("image") %>">
                	<%=cap.GetTexte("NOM") %> </option><%
              	 }
              	cap.Free(); %>
				</select>
			</td>
			<td align="right" style="width:30px;" class="petitblanc">nombre :&nbsp;</td>
			<td width="130px">
				<input type="text" name="nbcapsules" id="nbcapsules" maxlength="3" size="3" class="validate[required,custom[onlyNumberSp]]" autocomplete="off">
			</td>
        </tr>
        
        <tr>
        	<td>
                <p align="right" class="petitblanc" style="height:26px;">Prix unitaire :&nbsp;</p>
            </td>
            <td name="puht"><div id="div-puht"></div></td>
         </tr>
        <tr><td>
                <p align="right" class="petitblanc">Total :&nbsp;</p>
            </td>
            <td name="total"><%=new DecimalFormat("0.00").format(0) %>&#128;</td>
            <td>&nbsp;</td>
        </tr>
        <tr><td height="20px" width="100px"></td><td height="20px" width="265px"></td><td height="20px" width="30px"></td><td height="20px" width="130px"></td></tr>
    </table>
    <table width="98%">    
        <tr>
        	<td width="48%" align="right">
                <input class="boutons" type="submit" name="BValideLigne" value="Ajouter">
            </td>
            <td width="4%"></td>
        	<td width="48%" align="left">
                <input class="boutons" name="BValideLigne" id="bRetour" type="submit" value="Retour">
            </td>
        </tr>            
    </table>
</div>
</form>
<p align="center" class="petitrouge"><%=(request.getAttribute("BDD") != null) ? request.getAttribute("BDD") : "&nbsp;" %></p>
</div>
<script> //TODO : Retour même si le formulaire est KO

$(document).ready(function(e) {
	try {
		$("#capsules").msDropDown();
		$("#s_user").msDropDown();
	} catch(e) {
		alert(e.message);
	}
});

$(document).ready(function() {
	$("#FLigne").validationEngine({promptPosition : "centerRight", scroll: false, validationEventTrigger: "change"});
	
	$("#bRetour").click(function() {
		$("#FLigne").validationEngine('detach');
	});
	
	$("#nbcapsules").change(function() {
		var ncap = $("#capsules option:selected").text();
		$("#div-puht").html("Capsule <b>"+ncap+"</b> &#128;&nbsp;X&nbsp;10&nbsp;");
	});
});
document.getElementById('nbcapsules').focus();
</script>

</body>

</html>